home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6337 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: function similar to strtok() needed
  5. Date: 23 Feb 96 14:34:58 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.825086098@rscernix>
  8. References: <4gipop$igp@savvy2.savvy.com>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <4gipop$igp@savvy2.savvy.com> phil@savvy1.savvy.com (Phil Schwartz) writes:
  13.  
  14. >I want to be able to parse a line, say "this is a test&it better work!ok"
  15. >and grab the tokens which I will consider to be anything except the 
  16. >space (" "), ampersand ("&") and exclamation point ("!").  Strtok() seems to 
  17. >be a good starting point:
  18. ...
  19. >However, what if I want to know which of the characters (in tokens) was 
  20. >the separator between two tokens (tok)?  For example, when tok is "test" 
  21. >the separator was a space and when tok is "it", the separator is the 
  22. >ampersand.  
  23. >
  24. >I'm sure I could add write a hocked up routine to do this, but I figure 
  25. >there must be some elegant way of finding out this information.
  26.  
  27. Your guess is right and the name of the function is sscanf.  Read its
  28. description carefully.  If the (maximum) number of tokens is not known
  29. at compile time, you'll have to combine sscanf and strchr to get one
  30. token at a time from the string.
  31.  
  32. Dan
  33. --
  34. Dan Pop
  35. CERN, CN Division
  36. Email: danpop@mail.cern.ch 
  37. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  38.